﻿using System.Linq;

namespace ImageGallery.DAL
{
    public class PhotoDAO: GenericDAO<Photo>
    {
        public static Photo GetPhotoById(int photoID)
        {
            return IGEntitiesModel.Photos.Where(p=> p.PhotoID == photoID).SingleOrDefault();
        }

        public static void InsertPhoto(Photo photo)
        {
            IGEntitiesModel.Add(photo);
            SaveChanges();
        }

        public static void UpdatePhoto(Photo photo)
        {
            Photo updatedPhoto = GetPhotoById(photo.PhotoID);

            updatedPhoto.Title = photo.Title;
            updatedPhoto.Location = photo.Location;
            updatedPhoto.Description = photo.Description;
            updatedPhoto.Rating = photo.Rating;
            updatedPhoto.Data = photo.Data;
			updatedPhoto.RatesCount = photo.RatesCount;

            SaveChanges();
        }

        public static void DeletePhoto(int photoID)
        {
            Photo deletedPhoto = GetPhotoById(photoID);
            IGEntitiesModel.Delete(deletedPhoto);
            SaveChanges();
        }
    }
}
